<template>
  <div class="app-container">
    <!-- 查询和其他操作 -->
    <div class="filter-container">
      <el-input
        v-model="listQuery.storeName"
        clearable
        class="filter-item"
        style="width: 200px"
        placeholder="请输入门店名称"
      />
      <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="handleFilter"
        >查找</el-button
      >
      <!-- <el-button
        :loading="downloadLoading"
        class="filter-item"
        type="primary"
        icon="el-icon-download"
        @click="handleDownload"
      >导出</el-button>-->
    </div>

    <!-- 查询结果 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="正在查询中。。。"
      border
      fit
      highlight-current-row
    >
      <el-table-column
        align="center"
        width="100px"
        label="门店ID"
        prop="storeId"
        sortable
      />
      <el-table-column align="center" label="门店名称" prop="storeName" />
      <el-table-column align="center" label="门店地址" prop="address" />
      <el-table-column align="center" label="联系人" prop="contact" />
      <el-table-column align="center" label="联系方式" prop="contactPhone" />
      <el-table-column align="center" label="固定电话" prop="tel" />
      <el-table-column align="center" label="学生数量" prop="memberCount" />
      <el-table-column align="center" label="售卖课次" prop="saleCount" />
      <el-table-column align="center" label="剩余课次" prop="remainingCount" />
      <!-- <el-table-column align="center" label="门店账号" prop="loginId" /> -->
      <el-table-column align="center" label="创建时间" prop="created" />
      <el-table-column align="center" label="状态" prop="status">
        <template slot-scope="scope">
          <el-tag>{{ statusDic[scope.row.status] }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" prop="status" width="200px">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="onEdit(scope.row)"
            >编辑</el-button
          >
          <el-button type="primary" size="mini" @click="onShowClass(scope.row)"
            >耗课统计</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.size"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getStoreLsit } from '@/api/store/store'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination

export default {
  name: 'User',
  components: {
    Pagination,
  },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        index: 0,
        size: 20,
        storeName: undefined,
      },
      downloadLoading: false,
      genderDic: ['未知', '男', '女'],
      levelDic: ['普通用户', 'VIP用户', '高级VIP用户'],
      statusDic: ['启用', '禁用', '注销'],
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList(e) {
      if (e && e.page) {
        this.listQuery.index = e.page - 1
      }
      this.listLoading = true
      getStoreLsit(this.listQuery)
        .then((response) => {
          this.list = response.data.data.content
          this.total = response.data.data.totalRecords
          this.listLoading = false
        })
        .catch(() => {
          this.list = []
          this.total = 0
          this.listLoading = false
        })
    },
    handleFilter() {
      this.listQuery.page = 0
      this.getList()
    },
    onEdit(data) {
      this.$router.push({
        name: 'editShop',
        query: {
          data: JSON.stringify(data),
        },
      })
    },
    onShowClass(data) {
      this.$router.push({
        name: 'classtimelist',
        query: {
          storeId: data.storeId,
        },
      })
    },
    handleSizeChange(v) {
      console.log(v)
      this.listQuery.size = v
    },
  },
}
</script>
